package lib.quasar.widget.text;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

import lib.quasar.widget.R;

/**
 * description: 绿色圆背景
 * created by kalu on 2018/3/26 13:46
 */
public class CircleTextView extends AppCompatTextView {

    private int circleColor = Color.GREEN;

    /*******************************************************************************/

    public CircleTextView(Context context) {
        this(context, null, 0);
    }

    public CircleTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray array = null;
        try {

            Context applicationContext = context.getApplicationContext();
            array = applicationContext.obtainStyledAttributes(attrs, R.styleable.CircleTextView);
            circleColor = array.getColor(R.styleable.CircleTextView_ctv_circle_color, circleColor);

        } catch (Exception e) {

        } finally {
            if (null != array) {
                array.recycle();
            }
        }
    }

    /*******************************************************************************/

    @Override
    protected void onDraw(Canvas canvas) {

        getPaint().setColor(circleColor);
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, getPaint());

        super.onDraw(canvas);
    }

    public void setCircleColor(int mCircleColor) {
        this.circleColor = mCircleColor;
        postInvalidate();
    }
}
